package server.resources;

import game.CheapCompany;
import game.ExpensiveCompany;
import game.GameData;
import game.MediumCompany;
import game.Player;
import game.Tile;
import game.resources.Profile;
import game.resources.History.historyEntry;

import java.util.List;
import java.util.Map;

import server.Room;

import com.thoughtworks.xstream.XStream;

public class XMLFactory {
    public static String getRoomXML(Room room) {
        XStream xstream = new XStream();
        xstream.alias("roomState", Room.class);
        xstream.alias("profile", Profile.class);
        xstream.omitField(Profile.class, "history");
        xstream.omitField(Profile.class, "dirty");
        xstream.omitField(Profile.class, "addedHistory");
        
        return xstream.toXML(room);
    }
    
    public static Room getRoomFromXML(String room_state) {
        XStream xstream = new XStream();
        xstream.alias("roomState", Room.class);
        xstream.alias("profile", Profile.class);
        xstream.omitField(Profile.class, "history");
        xstream.omitField(Profile.class, "dirty");
        xstream.omitField(Profile.class, "addedHistory");
        
        return (Room) xstream.fromXML(room_state);
    }
    
    public static String getProfileXML(Profile profile) {
        XStream xstream = new XStream();
        xstream.alias("profile", Profile.class);
        xstream.alias("historyEntry", historyEntry.class);
        
        return xstream.toXML(profile);
    }
    
    public static String getGameDataXML(GameData gameData) {
        XStream xstream = new XStream();
        xstream.alias("GameData", GameData.class);
        xstream.alias("Tile", Tile.class);
        xstream.alias("CheapCompany", CheapCompany.class);
        xstream.alias("MediumCompany", MediumCompany.class);
        xstream.alias("ExpensiveCompany", ExpensiveCompany.class);
        xstream.alias("Tile", Tile.class);
        xstream.alias("Player", Player.class);
        return xstream.toXML(gameData);
    }
    
    public static GameData getGameDataFromXML(String gameDataXML) {
        XStream xstream = new XStream();
        xstream.alias("GameData", GameData.class);
        xstream.alias("Tile", Tile.class);
        xstream.alias("CheapCompany", CheapCompany.class);
        xstream.alias("MediumCompany", MediumCompany.class);
        xstream.alias("ExpensiveCompany", ExpensiveCompany.class);
        xstream.alias("Tile", Tile.class);
        xstream.alias("Player", Player.class);
        return (GameData)xstream.fromXML(gameDataXML);
    }
    
    public static String getHallOfFameXML(Map<Integer,List<Profile>> hof) {
        XStream xstream = new XStream();
        xstream.alias("Profile", Profile.class);        
        xstream.omitField(Profile.class, "history");
        xstream.omitField(Profile.class, "dirty");
        xstream.omitField(Profile.class, "addedHistory");
        xstream.omitField(Profile.class, "rating");
        
        return xstream.toXML(hof);        
    }
    
}
